# cython: language_level=3
import datetime, time, re

# 获取标准时间字符串
def get_str_datetime():
    cdef object value = datetime.datetime.now()
    cdef str data = value.__str__()[:19]
    return data

# 获取utc时间戳
def get_utc():
    cdef int value = int(time.time())
    return value

# 获取无符号时间字符串
def get_number_datetime():
    cdef str value=get_str_datetime()
    value = value.replace('-', '').replace(':', '').replace(' ', '')
    return value

# 获取datetime时间对象
def get_datetime():
    return datetime.datetime.now()

# 转为标准时间字符串
def str_to_str_datetime(s):
    value = (int(v) for v in re.findall('\d+', s))
    return datetime.datetime(*value).__str__()

# 转为无符号时间字符串
def str_to_number_datetime(s):
    value = "".join(re.findall('\d+', s))
    return value

# 转为datetime时间对象
def str_to_datetime(s):
    value = str_to_str_datetime(s)
    value = (int(v) for v in re.findall('\d+', value))
    return datetime.datetime(*value)

# 转为utc时间戳
def str_datetime_to_utc(s):
    value = str_to_str_datetime(s)
    utc = int(time.mktime(time.strptime(value, '%Y-%m-%d %H:%M:%S')))
    return utc

# 时间戳转为时间对象
def utc_to_datetime(s):
    str_datetime = utc_to_str_datetime(s)
    value = str_to_datetime(str_datetime)
    return value

# 时间戳转为时间字符串
def utc_to_str_datetime(s):
    fmt = "%Y-%m-%d %H:%M:%S"
    value = time.strftime(fmt, time.localtime(int(s)))
    return value

# 时间戳转为无符号时间字符串
def utc_to_number_datetime(s):
    value = utc_to_str_datetime(s)
    return str_to_number_datetime(value)

# 无符号时间转为标准时间
def number_to_str_datetime(s):
    s = str(s)
    value = (s[:4] if i == 0 else s[(i + 1) * 2:(i + 2) * 2] for i in range(int((len(s) - 4) / 2) + 1))
    return "{}-{}-{} {}:{}:{}".format(*value)
    # return "{}-{}-{} {}:{}:{}".format(s[:4], s[4:6], s[6:8], s[8:10], s[10:12], s[12:14])

# 无符号时间转为datetime对象
def number_to_datetime(s):
    _str = number_to_str_datetime(s)
    value = str_to_datetime(_str)
    return value

# 无符号时间转为时间戳
def number_to_utc(s):
    value = number_to_str_datetime(s)
    return str_datetime_to_utc(value)

# 时间对像转为utc时间戳
def datetime_to_utc(s):
    value = s.__str__()[:19]
    return str_datetime_to_utc(value)

# 时间对像转为标准时间字符串
def datetime_to_str_datetime(s):
    value = s.__str__()[:19]
    return value

# 时间对像转为无符号时间字符串
def datetime_to_number_datetime(s):
    value = datetime_to_str_datetime(s)
    return str_to_number_datetime(value)

#
# a=get_utc()
# print('utc',a)
# print('number',utc_to_number_datetime(a))
# print('str',utc_to_str_datetime(a))
# print('datetime',utc_to_datetime(a),type(utc_to_datetime(a)))
#
# a='2021 11 12 00 11 59'
# print('str',str_to_str_datetime(a))
# print('utc',str_datetime_to_utc(a))
# print(111,'datetime',str_to_datetime(a),type(str_to_datetime(a)))
# print('num',str_to_number_datetime(a))
#
# a = 2012111211111112
# value = number_to_str_datetime(a)
#
# print(555, value, type(value))
# print(6666,number_to_utc(a))
# print(7777,type(number_to_datetime(a)))
# print(8888,number_to_str_datetime(a))